// 对手机号进行脱敏处理
function desensitizePhone(phone) {
    if (typeof phone !== 'string') return phone
    return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
}

// 组装评论列表一级评论和子评论
function handleCommentData(fData, cData) {
    let arr = []
    fData.forEach(item => {
        item.children = []
        if (!item.parentId) {
            arr.push(item)
        }
    })

    arr.forEach(item => {
        cData.forEach(child => {
            if (item.commentId === child.rootId) {
                item.children.push(child)
            }
        })
    })

    return arr
}

module.exports = {
    desensitizePhone,
    handleCommentData
}
